package cn.shone.hubu.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

import cn.shone.hubu.po.HbMember;

/**
 * Data access object (DAO) for domain model class HbMember.
 * 
 * @see cn.shone.hubu.po.HbMember
 * @author MyEclipse Persistence Tools
 */

public class HbMemberDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(HbMemberDAO.class);

	// property constants
	public static final String USERNAME = "username";

	public static final String PASSWORD = "password";

	public static final String USERTYPE = "usertype";

	public static final String USERLEVEL = "userlevel";

	public static final String PHONEFLAG = "phoneflag";

	public static final String PHONECOST = "phonecost";

	public static final String RECID = "recid";

	public static final String EMAIL = "email";

	public static final String REALNAME = "realname";

	public static final String SEX = "sex";

	public static final String BIRTHDAY = "birthday";

	public static final String BRIEF = "brief";

	public static final String COUNTRY = "country";

	public static final String CITY = "city";

	public static final String DISTRICT = "district";

	public static final String ADDRESS = "address";

	public static final String ZIPCODE = "zipcode";

	public static final String MOBILE = "mobile";

	public static final String PHONE = "phone";

	public static final String QQ = "qq";

	public static final String MSN = "msn";

	public static final String BIGPIC = "bigpic";

	public static final String SMALLPIC = "smallpic";

	public static final String QUESTION = "question";

	public static final String ANSWER = "answer";

	public static final String PAYPWD = "paypwd";

	public static final String GRADE1 = "grade1";

	public static final String GRADE2 = "grade2";

	public static final String BALANCE = "balance";

	public static final String CREDITS1 = "credits1";

	public static final String CREDITS2 = "credits2";

	public static final String CREDITSIN = "creditsin";

	public static final String CREDITSOUT = "creditsout";

	public void save(HbMember transientInstance) {
		log.debug("saving HbMember instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(HbMember persistentInstance) {
		log.debug("deleting HbMember instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public HbMember findById(java.lang.Integer id) {
		log.debug("getting HbMember instance with id: " + id);
		try {
			HbMember instance = (HbMember) getSession().get(
					"cn.shone.hubu.po.HbMember", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(HbMember instance) {
		log.debug("finding HbMember instance by example");
		try {
			List results = getSession().createCriteria(
					"cn.shone.hubu.po.HbMember").add(Example.create(instance))
					.list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding HbMember instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from HbMember as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByUsername(Object username) {
		return findByProperty(USERNAME, username);
	}

	public List findByPassword(Object password) {
		return findByProperty(PASSWORD, password);
	}

	public List findByUsertype(Object usertype) {
		return findByProperty(USERTYPE, usertype);
	}

	public List findByUserlevel(Object userlevel) {
		return findByProperty(USERLEVEL, userlevel);
	}

	public List findByPhoneflag(Object phoneflag) {
		return findByProperty(PHONEFLAG, phoneflag);
	}

	public List findByPhonecost(Object phonecost) {
		return findByProperty(PHONECOST, phonecost);
	}

	public List findByRecid(Object recid) {
		return findByProperty(RECID, recid);
	}

	public List findByEmail(Object email) {
		return findByProperty(EMAIL, email);
	}

	public List findByRealname(Object realname) {
		return findByProperty(REALNAME, realname);
	}

	public List findBySex(Object sex) {
		return findByProperty(SEX, sex);
	}

	public List findByBirthday(Object birthday) {
		return findByProperty(BIRTHDAY, birthday);
	}

	public List findByBrief(Object brief) {
		return findByProperty(BRIEF, brief);
	}

	public List findByCountry(Object country) {
		return findByProperty(COUNTRY, country);
	}

	public List findByCity(Object city) {
		return findByProperty(CITY, city);
	}

	public List findByDistrict(Object district) {
		return findByProperty(DISTRICT, district);
	}

	public List findByAddress(Object address) {
		return findByProperty(ADDRESS, address);
	}

	public List findByZipcode(Object zipcode) {
		return findByProperty(ZIPCODE, zipcode);
	}

	public List findByMobile(Object mobile) {
		return findByProperty(MOBILE, mobile);
	}

	public List findByPhone(Object phone) {
		return findByProperty(PHONE, phone);
	}

	public List findByQq(Object qq) {
		return findByProperty(QQ, qq);
	}

	public List findByMsn(Object msn) {
		return findByProperty(MSN, msn);
	}

	public List findByBigpic(Object bigpic) {
		return findByProperty(BIGPIC, bigpic);
	}

	public List findBySmallpic(Object smallpic) {
		return findByProperty(SMALLPIC, smallpic);
	}

	public List findByQuestion(Object question) {
		return findByProperty(QUESTION, question);
	}

	public List findByAnswer(Object answer) {
		return findByProperty(ANSWER, answer);
	}

	public List findByPaypwd(Object paypwd) {
		return findByProperty(PAYPWD, paypwd);
	}

	public List findByGrade1(Object grade1) {
		return findByProperty(GRADE1, grade1);
	}

	public List findByGrade2(Object grade2) {
		return findByProperty(GRADE2, grade2);
	}

	public List findByBalance(Object balance) {
		return findByProperty(BALANCE, balance);
	}

	public List findByCredits1(Object credits1) {
		return findByProperty(CREDITS1, credits1);
	}

	public List findByCredits2(Object credits2) {
		return findByProperty(CREDITS2, credits2);
	}

	public List findByCreditsin(Object creditsin) {
		return findByProperty(CREDITSIN, creditsin);
	}

	public List findByCreditsout(Object creditsout) {
		return findByProperty(CREDITSOUT, creditsout);
	}

	public List findAll() {
		log.debug("finding all HbMember instances");
		try {
			String queryString = "from HbMember";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public HbMember merge(HbMember detachedInstance) {
		log.debug("merging HbMember instance");
		try {
			HbMember result = (HbMember) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(HbMember instance) {
		log.debug("attaching dirty HbMember instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(HbMember instance) {
		log.debug("attaching clean HbMember instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}